package com.example.sls.dao.social;

import com.example.sls.pojo.social.ActivityRegistrations;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 活动报名表(ActivityRegistrations)表数据库访问层
 *
 * @author makejava
 * @since 2024-06-18 10:55:00
 */
public interface ActivityRegistrationsDao {
  /**
   * 通过ID查询单条数据
   *
   * @param id 主键
   * @return 实例对象
   */
  @Select("select * from activity_registrations where id=#{id}")
  ActivityRegistrations queryById(Integer id);

  /**
   * 查询指定行数据
   *
   * @param activityRegistrations 查询条件
   * @param pageSize              分页对象
   * @param offset                偏移量，起始处
   * @return 对象列表
   */
  @Select("select * from activity_registrations where 1=1" +
          " and (id=#{activityRegistrations.id} or (isnull(#{activityRegistrations.id}) or #{activityRegistrations.id}=0))" +
          " and (activity_id=#{activityRegistrations.activityId} or (isnull(#{activityRegistrations.activityId}) or #{activityRegistrations.activityId}=0))" +
          " and (user_id=#{activityRegistrations.userId} or (isnull(#{activityRegistrations.userId}) or #{activityRegistrations.userId}=0))" +
          " and (registration_time=#{activityRegistrations.registrationTime} or (isnull(#{activityRegistrations.registrationTime}) or #{activityRegistrations.registrationTime}=''))" +
          " limit #{pageSize} offset #{offset}")
  List<ActivityRegistrations> queryAllByLimit(ActivityRegistrations activityRegistrations, Integer pageSize, Integer offset);

  /**
   * 统计总行数
   *
   * @return 总行数
   */
  @Select("select count(*) from activity_registrations")
  long count();

  /**
   * 新增数据
   *
   * @param activityRegistrations 实例对象
   * @return 影响行数
   */
  @Insert("insert into activity_registrations (id,activity_id,user_id,registration_time) " +
          "values(" +
          "if(#{id}!=0 and !isnull(#{id}),#{id},null)," +
          "if(#{activityId}!=0 and !isnull(#{activityId}),#{activityId},null)," +
          "if(#{userId}!=0 and !isnull(#{userId}),#{userId},null)," +
          "if(#{registrationTime}!='' and !isnull(#{registrationTime}),#{registrationTime},null)" +
          ")")
  int insert(ActivityRegistrations activityRegistrations);

  /**
   * 通过id修改数据
   * id 主键
   *
   * @param activityRegistrations 实例对象
   * @return 影响行数
   */
  @Update("update activity_registrations set " +
          "activity_id=if(isnull(#{activityId}) or #{activityId}=0,activity_id,#{activityId})," +
          "user_id=if(isnull(#{userId}) or #{userId}=0,user_id,#{userId})," +
          "registration_time=if(isnull(#{registrationTime}) or #{registrationTime}='',registration_time,#{registrationTime})" +
          " where id=#{id}")
  int update(ActivityRegistrations activityRegistrations);

  /**
   * 通过主键删除数据
   *
   * @param id 主键
   * @return 影响行数
   */
  @Delete("delete from activity_registrations where id=#{id}")
  int deleteById(Integer id);
}

